﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.goods {
    import flash.events.*;
    import org.robotlegs.core.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class GoodsButtonMediator extends Mediator implements IMediator {

		[Inject]
        public var goodsButton:GoodsButton;
		[Inject]
        public var contractsModel:ContractsModel;
		[Inject]
        public var worldModel:WorldModel;
		[Inject]
        public var roomSlotsModel:RoomSlotsModel;
		[Inject]
        public var userModel:UserModel;

        override public function onRegister():void{
            this.goodsButton.init();
            eventMap.mapListener(eventDispatcher, EventConstants.UPDATED_CONTRACT, this.updateState);
            eventMap.mapListener(eventDispatcher, EventConstants.VISIT_FRIEND, this.onVisitFriend);
            this.goodsButton.addEventListener(MouseEvent.CLICK, this.onButtonClick);
            this.updateState();
        }
        private function updateState(_arg1:InfoEvent=null):void{
            switch (this.contractsModel.state){
                case ContractsModel.DELIVER_GOODS:
                case ContractsModel.READY_TO_FINALIZE:
                    this.goodsButton.show();
                    break;
                case ContractsModel.READY_TO_CREATE:
                case ContractsModel.WAITING:
                default:
                    this.goodsButton.hide();
                    break;
            };
        }
        private function onButtonClick(_arg1:MouseEvent):void{
            var _local2:String = this.worldModel.getRoomIdsOfType(GameConstants.TYPE_DOCK)[0];
            var _local3:IRoom = (this.worldModel.getRoomById(_local2) as IRoom);
            var _local4:Slot = this.roomSlotsModel.getSlotById(_local3.slotId);
            dispatch(new InfoEvent(EventConstants.SHOW_ROOM, String(_local4.id)));
        }
        private function onVisitFriend(_arg1:Event):void{
            if (this.userModel.isVisitFriendsMode()){
                this.goodsButton.hide();
            };
        }

    }
}//package net.wooga.pets.views.goods 
